﻿using Hangfire.States;
using Hangfire.Storage;

namespace AiQiuQuan.Sport.Core.Hangfire
{
    /// <summary>
    /// hangfire 成功记录删除
    /// </summary>
    public class SucceededStateExpireHandler : IStateHandler
    {
        private readonly TimeSpan _jobExpirationTimeout;

        /// <summary>
        /// ctor
        /// </summary>
        public SucceededStateExpireHandler(int jobExpirationTimeout)
        {
            _jobExpirationTimeout = TimeSpan.FromMinutes(jobExpirationTimeout);
        }

        /// <summary>
        /// 状态
        /// </summary>
        public string StateName => SucceededState.StateName;

        /// <summary>
        /// 运用
        /// </summary>
        public void Apply(ApplyStateContext context, IWriteOnlyTransaction transaction)
        {
            context.JobExpirationTimeout = _jobExpirationTimeout;
        }

        /// <summary>
        /// 禁用
        /// </summary>
        public void Unapply(ApplyStateContext context, IWriteOnlyTransaction transaction)
        {
        }
    }
}
